package cn.lzm.org.controller;

import cn.lzm.basic.util.AjaxResult;
import cn.lzm.basic.util.PageList;
import cn.lzm.org.domain.SystemDictionaryType;
import cn.lzm.org.query.SystemDictionaryTypeQuery;
import cn.lzm.org.service.ISystemDictionaryDetailService;
import cn.lzm.org.service.ISystemDictionaryTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/sdt")
public class SystemDictionaryTypeController {
    @Autowired
    private ISystemDictionaryTypeService systemDictionaryTypeService;
    @Autowired
    private ISystemDictionaryDetailService systemDictionaryDetailService;
    /**
     * 添加/修改
     */
    @PostMapping("/addorup")
    public AjaxResult addOrUpdate(@RequestBody SystemDictionaryType systemDictionaryType){
        if (  null == systemDictionaryType.getId()) {
            systemDictionaryTypeService.add(systemDictionaryType);
        } else {
            systemDictionaryTypeService.update(systemDictionaryType);
        }
        return  AjaxResult.me().success();
    }

    /**
     * 删除
     */
    @DeleteMapping("/{id}")
    public AjaxResult deleteAll(@PathVariable("id") Long id) { // @PathVariable("id")接收变量的注解 id必须一样
        systemDictionaryTypeService.deleteALL(id);
        return AjaxResult.me().success();
    }


    /**
     * 查询所有
     */
    @GetMapping
    public List<SystemDictionaryType> findAll(){
        return systemDictionaryTypeService.queryAll();
    }

    /**
     * 根据id查询一个
     */
    @GetMapping("/{id}")
    public SystemDictionaryType findById(@PathVariable("id") Long id){
        return systemDictionaryTypeService.queryById(id);
    }

    /**
     *
     * 分页查询
     */
    @PostMapping
    public PageList<SystemDictionaryType> queryByPage(@RequestBody SystemDictionaryTypeQuery query){
//        System.out.println(query);
//        System.out.println(query.getCurrentPage());
//        System.out.println(query.getPageSize());
        return systemDictionaryTypeService.queryPage(query);
    }

}
